XNA Game Class


4. XNA Game Class



4.1. To make the game operate you have to define a lot of variables/objects. The below image details the members of the GameClass object and the members we are using. If also shows all of the methods that are used throughout the game.


LP3-401.jpg



4.2. We start off declaring all of the class members that we will use in the program. I described several of the main ones in previous part of the report.


LP3-402.jpg


4.3. We continue to declare variables. We also define the List Objects that we use to track all of the data that is on the screen.


LP3-403.jpg


4.4. The game constructor sets up the Quadrant object as well as the Menu object. There is also an option to run the game in full screen mode.


LP3-404.jpg


4.5. The load content start to get all of the objects declared for the game environment.


LP3-405.jpg


4.6. The remaining portion of the load content method.


LP3-406.jpg


4.7. The GameReset method was created so we could restart the game with now objects every time you select the start from the main menu.


LP3-407.jpg
LP3-407A.jpg


4.8. The Unload Content method is not utilized at this point.


LP3-408.jpg


4.9. The update method is where we have the logic between the menu class and the actual game objects. We have some global keyboard options that effect game play. They are Q which exits you from the game, P which will pause the game, and M which will mute the sound.


LP3-409.jpg


4.10. The main feature of the Update method is the GameState variable. This Boolean checks to see if the game has been started. If it has it goes through the operations the game needs to do to make it work. Such as moving the ship and firing the lasers. If the escape key is hit it will take you back to the main menu.


LP3-410.jpg


4.11. If the game is in menu mode it looks for a start state to start the game. If the ship has collected the correct amount of Ore the ship teleportation graphic is started and the teleport counter is incremented.


LP3-411.jpg


4.12. After the check for game state and for the win, the game works through all of the objects in the game.


LP3-412.jpg


4.13. The update laser method looks to see if the laser is alive and moves it to its next position. It also checks to see if it encounters any asteroids. If it does it runs the explosion sound and animation.


LP3-413.jpg


4.14. If the asteroid state is large the rock produces two medimum asteroids and releases elements. If it is edimum it adds two small asteroids to the screen.


LP3-414.jpg


4.15. If the asteroid is small it is destroyed. Then the laser method looks for enemy ships


LP3-415.jpg


4.16. It looks for bugs.


LP3-416.jpg


4.17. Then it looks for enemy lasers


LP3-417.jpg


4.18. The update elements looks to see if the ship collected it.


LP3-418.jpg


4.19. This method adds the amount of ore mined to the display counter.


LP3-419.jpg


4.20. The fire laser method sets the laser on the correct path from the ship and activates it.


LP3-420.jpg


4.21. If there is enough laser fuel the lasers can be upgraded to shoot more that one.


LP3-421.jpg
LP3-421A.jpg


4.22. The update asteroids method starts out by rotating the asteroid.


LP3-422.jpg


4.23. Then it looks to see if the shop hits a rock. If it does it destroys the entire rock and reduces the ships hit counter.


LP3-423.jpg


4.24. This method looks to see if the ship collides with an enemy ship.


LP3-424.jpg


4.25. The update Bugs method looks for os3 ore and will collect it if it is available.


LP3-425.jpg


4.26. The FireEnemyLaser fires lasers at the main ship when it collects os3 ore.


LP3-426.jpg


4.27. The GetRandomPositionOnScreen gets random coordinates for objects and places them in their random quadrants.


LP3-427.jpg


4.28. These methods get random images to change up the look and feel of the game.


LP3-428.jpg


4.29. These methods get random images to change up the look and feel of the game.


LP3-429.jpg


4.30. Creates additional asteroids when a larger one is destroyed.


LP3-430.jpg


4.31. This method makes the bug go towards the os3 when it is available. The SendMiningAlert produces a sound and tells the player that they got some os3.


LP3-431.jpg


4.32. The Draw method writes all of the graphics to the screen. If the menu is enabled it just draws the menu screen. Otherwise it will start by drawing the ship, with animation if it is moving.


LP3-432.jpg


4.33. Draws explosions, asteroids, lasers…


LP3-433.jpg


4.34. elements, enemy ships, bugs, …


LP3-434.jpg


4.35. and finally enemy lasers. Then it checks for a win status and draws the teleportation graphic if there is a win state.


LP3-435.jpg


4.36. If there is no win state then the ship was destroyed. After the main assets are drawn the data for the status menu is drawn.


LP3-436.jpg
LP3-436A.jpg

Project Home Next Section